﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

/// <summary>
///CXSecurity 的摘要说明
/// </summary>
public class CXSecurity
{
	public CXSecurity()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}
    public const int PManagerRead = 1; //项目管理.浏览  
    public const int PManagerUpdate = 2; //项目管理.修改 
    public const int PManagerCreate = 4; //项目管理.创建 
    public const int PManagerDelete = 8; //项目管理.删除 
    public const int PManagerMark = 16; //项目管理.评分
    public const int PManagerVerify = 32; //项目管理.审核
    public const int PManagerMaster = 64; //项目管理.领导
     

    /// <summary>
    /// 按位或比较运算
    /// </summary>
    /// <param name="a">权限比较值(非幂值)</param>
    /// <param name="b">总权限值(幂值)</param>
    /// <returns>返回Bool值,确定是否具有权限</returns>
    public static bool Check(int a,int b)
    {
        a = Mi(a);
        if((a&b)==a)
        {
            return true;
        }
        return false;
    }
    /// <summary>
    /// 获取幂值
    /// </summary>
    /// <param name="i">传递计算参数i</param>
    /// <returns>返回幂值</returns>
    public static int Mi(int i)
    {
        i = int.Parse(Math.Pow(2, i).ToString());
        return i;
    }
    public static void ChkDept(string deptid)
    {
        if (Cookies.getCookies("cDeptID") != deptid)
        {
            HttpContext.Current.Response.Redirect("~/err.aspx");
        }
    }
    public static void ChkBoss(string uid)
    {
        if (Cookies.getCookies("cLevelID") != "1")
        {
            HttpContext.Current.Response.Redirect("~/err.aspx");
        }
    }
    public static void ChekBigBoss()
    {
        if (Cookies.getCookies("cdeptid") != "1" || Cookies.getCookies("clevelid") != "1")
        {
            HttpContext.Current.Response.Redirect("~/err.aspx");
        }
    }
}
